package com.tl.web.controller.app;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.tl.common.annotation.Log;
import com.tl.common.core.controller.BaseController;
import com.tl.common.core.domain.AjaxResult;
import com.tl.common.enums.BusinessType;
import com.tl.app.domain.AppOrderItem;
import com.tl.app.service.IAppOrderItemService;
import com.tl.common.utils.poi.ExcelUtil;
import com.tl.common.core.page.TableDataInfo;

/**
 * 子订单Controller
 * 
 * @author suhp
 * @date 2024-08-01
 */
@RestController
@RequestMapping("/app/orderItem")
public class AppOrderItemController extends BaseController
{
    @Autowired
    private IAppOrderItemService appOrderItemService;

    /**
     * 查询子订单列表
     */
    @PreAuthorize("@ss.hasPermi('app:orderItem:list')")
    @GetMapping("/list")
    public TableDataInfo list(AppOrderItem appOrderItem)
    {
        startPage();
        List<AppOrderItem> list = appOrderItemService.selectAppOrderItemList(appOrderItem);
        return getDataTable(list);
    }

    /**
     * 导出子订单列表
     */
    @PreAuthorize("@ss.hasPermi('app:orderItem:export')")
    @Log(title = "子订单", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, AppOrderItem appOrderItem)
    {
        List<AppOrderItem> list = appOrderItemService.selectAppOrderItemList(appOrderItem);
        ExcelUtil<AppOrderItem> util = new ExcelUtil<AppOrderItem>(AppOrderItem.class);
        util.exportExcel(response, list, "子订单数据");
    }

    /**
     * 获取子订单详细信息
     */
    @PreAuthorize("@ss.hasPermi('app:orderItem:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(appOrderItemService.selectAppOrderItemById(id));
    }

    /**
     * 新增子订单
     */
    @PreAuthorize("@ss.hasPermi('app:orderItem:add')")
    @Log(title = "子订单", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody AppOrderItem appOrderItem)
    {
        return toAjax(appOrderItemService.insertAppOrderItem(appOrderItem));
    }

    /**
     * 修改子订单
     */
    @PreAuthorize("@ss.hasPermi('app:orderItem:edit')")
    @Log(title = "子订单", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody AppOrderItem appOrderItem)
    {
        return toAjax(appOrderItemService.updateAppOrderItem(appOrderItem));
    }

    /**
     * 删除子订单
     */
    @PreAuthorize("@ss.hasPermi('app:orderItem:remove')")
    @Log(title = "子订单", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(appOrderItemService.deleteAppOrderItemByIds(ids));
    }
}
